#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;
#include <vector>

void MergeSort(vector<int>& nums, vector<int>& temp, int left, int right)
{
	if (left >= right) return;
	srand(0);
	int mid = left + (right - left) / 2;

	MergeSort(nums, temp, left, mid);
	MergeSort(nums, temp, mid + 1, right);

	int begin1 = left, end1 = mid, begin2 = mid + 1, end2 = right;
	int i = 0;
	while (begin1 <= end1 && begin2 <= end2)
		temp[i++] = nums[begin1] <= nums[begin2] ? nums[begin1++] : nums[begin2++];

	while (begin1 <= end1) temp[i++] = nums[begin1++];
	while (begin2 <= end2) temp[i++] = nums[begin2++];

	for (int i = left; i <= right; i++)
	{
		nums[i] = temp[i - left];
	}
}

int main()
{
	vector<int> nums = { 1,43,76,1,2,0,56,3,8,54,87,23 };
	vector<int> temp(nums.size());
	MergeSort(nums, temp, 0, nums.size() - 1);
	for (auto e : nums)
	{
		cout << e << ' ';
	}

	return 0;
}